package leetcode.N1_N100;

import com.google.common.collect.Maps;
import leetcode.comm.ListNode;

import java.util.Map;

public class N21 {


    public static void main(String[] args) {
        ListNode l1 = ListNode.generate(1, 2, 4);
        ListNode l2 = ListNode.generate(1, 3, 4);
        System.out.println(mergeTwoLists_1(l1, l2));
    }

    private static ListNode mergeTwoLists_1(ListNode l1, ListNode l2) {
        ListNode result = new ListNode(0);
        ListNode offset = result;
        while (true) {
            if (l1 == null) {
                offset.next = l2;
                break;
            }
            if (l2 == null) {
                offset.next = l1;
                break;
            }
            if (l1.val > l2.val) {
                offset = offset.next = l2;
                l2 = l2.next;
            } else {
                offset = offset.next = l1;
                l1 = l1.next;
            }
        }
        return result.next;
    }


}
